# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=scopehal-apps
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.0.r1312.g1f47d350
pkgrel=2
pkgdesc="scopehal-apps: applications for libscopehal (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/azonenberg/scopehal-apps"
license=('spdx:BSD-3-Clause')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-glm"
  "${MINGW_PACKAGE_PREFIX}-libsigc++"
  "${MINGW_PACKAGE_PREFIX}-gtkmm3"
  "${MINGW_PACKAGE_PREFIX}-yaml-cpp"
  "${MINGW_PACKAGE_PREFIX}-glew"
  "${MINGW_PACKAGE_PREFIX}-ffts"
  $([[ ${MINGW_PACKAGE_PREFIX} != *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-openmp")
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "git"
)
_commit='1f47d350'
source=("${_realname}::git+https://github.com/azonenberg/scopehal-apps.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}"
  printf "0.0.0.r%s.g%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short=8 ${_commit})"
}

prepare() {
  cd "${srcdir}/${_realname}"
  git remote set-url origin https://github.com/azonenberg/scopehal-apps
  git submodule update --init --recursive
}

build() {
  cd "${srcdir}"
  [ -d build-${MSYSTEM} ] && rm -rf build-${MSYSTEM}
  mkdir -p build-${MSYSTEM}
  cd build-${MSYSTEM}

  CMAKE="${MINGW_PREFIX}/bin/cmake.exe"

  CXXFLAGS+=" -Wno-format" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  $CMAKE \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DBUILD_TESTING=OFF \
    ../${_realname}

  $CMAKE --build ./
}

check() {
  "${srcdir}/${_realname}"/build/src/glscopeclient/glscopeclient.exe --help
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 "${srcdir}/${_realname}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
